package org.itcast.annotationandresttemplate.swaggerTest.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.itcast.adi.planinfo.entity.ResultBean;
import org.itcast.annotationandresttemplate.swaggerTest.entity.PageResult;
import org.itcast.annotationandresttemplate.swaggerTest.entity.SwaggerDTO;
import org.itcast.annotationandresttemplate.swaggerTest.service.SwaggerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * springboot 2.x版本整合swagger常用注解：
 *
 * @Api: 用在类上，例如controller，表示对类的说明
 * @ApiModel: 用在类上，例如，entity，DTO，VO
 * @ApiModelProperty: 用在属性上，描述属性信息
 * @ApiOperation: 用在方法上，例如Controller的方法，说明方法的用途，作用
 */
@RestController
@RequestMapping("/swagger")
@Tag(name = "Swagger测试基础服务")
public class SwaggerController {

    @Autowired
    private SwaggerService swaggerService;

    @PostMapping("/save")
    @Operation(summary = "新增数据")
    public ResultBean save(@RequestBody SwaggerDTO swaggerDTO) {
        swaggerService.save(swaggerDTO);
        return ResultBean.success();
    }

    @GetMapping("/find")
    @Operation(summary = "查询数据")
    public ResultBean find(SwaggerDTO swaggerDTO) {
        List<SwaggerDTO> swaggerDTOS = swaggerService.find(swaggerDTO);
        return ResultBean.success(swaggerDTOS);
    }

    //    分页查询
    @GetMapping("/page")
    @Operation(summary = "分页查询数据")
    public ResultBean findByName(SwaggerDTO swaggerDTO) {
        PageResult pageResult = swaggerService.findByPage(swaggerDTO);
        return ResultBean.success(pageResult);
    }
}
